/*
 * LoginDAO.java
 *
 * Created on 16 de Junho de 2009, 14:19
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package sisnutri.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleBlobInputStream;
import sisnutri.OracleConnectionFactory;

/**
 *
 * @author Bruno
 */
public class LoginDAO {
    
    /** Creates a new instance of LoginDAO */
    public LoginDAO() {
    }

    public boolean login(String crn, String senha) {
        ResultSet rs = null;
        
        try {
            Connection con = OracleConnectionFactory.getConnection();
            String sql = "SELECT   N.crn,   N.senha FROM TB_NUTRICIONISTA N " +
                    "where N.crn = ? and N.senha = ?";
            PreparedStatement stm = con.prepareStatement(sql);
            
            stm.setString(1, crn);
            stm.setString(2, senha);
            
            rs = stm.executeQuery();
            
            if(!rs.next()) return false;
            
            while (true) {
                String login = rs.getString(1);
                String key = rs.getString(2);
                if (!rs.next()) break;
            }
            con.close();
            stm.close();
            rs.close();
            return true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
    
    
}
